package cn.com.selfsoft.smartcity.core.controller;

import cn.com.selfsoft.smartcity.commons.http.DataItem;
import cn.com.selfsoft.smartcity.commons.http.DataList;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;

/**
 *
 *
 */
public interface GenericController<T, K> {

	/**
	 * GET 获取符合查询条件的记录数
	 * 
	 * @param request
	 * @return
	 */
	ResponseEntity<Long> count(HttpServletRequest request);
	
	/**
	 * 
	 * @param request
	 * @param page
	 * @return
	 */
	ResponseEntity<DataPage> page(HttpServletRequest request, Pageable page);
	
	/**
	 * GET 获取符合查询条件的记录
	 * 
	 * @param request
	 * @return
	 */
	ResponseEntity<DataList> list(HttpServletRequest request, Sort sort);

	/**
	 * GET 通过标识获取一条记录
	 * 
	 * @param id
	 * @param request
	 * @return
	 */
	ResponseEntity<DataItem> load(K id, HttpServletRequest request);
	
	/**
	 * DELETE 通过标识删除一条记录
	 * 
	 * @param id
	 * @param request
	 * @return
	 */
	ResponseEntity<Void> delete(K id, HttpServletRequest request);
	
	/**
	 * POST 创建一条记录
	 * 
	 * @param entity
	 * @param request
	 * @return
	 */
	ResponseEntity<DataItem> create(T entity, HttpServletRequest request);
	
	/**
	 * PUT 修改一条记录
	 * 
	 * @param id
	 * @param entity
	 * @param request
	 * @return
	 */
	ResponseEntity<DataItem> update(K id, T entity, HttpServletRequest request);
	
}
